package com.ruoyi.pingan.fymodule.separateSetting.categorytemplate.controller;

import java.util.HashSet;
import java.util.Random;
import java.util.Set;

public class UniqueIdGenerator {
    private static final Random random = new Random();
    private static final Set<Integer> generatedIds = new HashSet<>();

    public static String generateUniqueId() {
        int id;
        do {
            id = random.nextInt(10000); // 生成0到9999之间的随机数
        } while (generatedIds.contains(id));

        generatedIds.add(id);
        return String.format("%04d", id); // 返回四位数字字符串
    }

    public static void main(String[] args) {
        // 测试生成多个不重复的四位ID
        for (int i = 0; i < 20; i++) {
            System.out.println(generateUniqueId());
        }
    }
}